/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InformeDialog.java
 *
 * Created on 28-feb-2010, 11:29:28
 */

package es.atareao.ferraplan.gui;

import es.atareao.alejandria.gui.ErrorDialog;
import es.atareao.alejandria.lib.DateUtils;
import es.atareao.ferraplan.lib.Elaborador;
import es.atareao.ferraplan.lib.Montador;
import es.atareao.queensboro.file.CompactDb;
import java.sql.SQLException;
import java.util.Date;

/**
 *
 * @author atareao
 */
public class DialogReportMontador extends javax.swing.JDialog {
    //
    //********************************CONSTANTES********************************
    //
    /** A return status code - returned if Cancel button has been pressed */
    public static final int RET_CANCEL = 0;
    /** A return status code - returned if OK button has been pressed */
    public static final int RET_OK = 1;
    //
    //
    //******************************CONSTRUCTORES*******************************
    //
    /** Creates new form InformeDialog */
    public DialogReportMontador(java.awt.Frame parent, boolean modal,CompactDb cdb) {
        super(parent, modal);
        initComponents();
        this.setSize(410, 240);
        this.setLocationRelativeTo(null);
        this.jDesde.setDate(DateUtils.addMonths(DateUtils.Ahora(), -1));
        this.jHasta.setDate(DateUtils.Ahora());
        try {
            Montador montador=new Montador(cdb.getConector());
            this.jMontador.setElements(montador.find("orden"));
        } catch (SQLException ex) {
            ErrorDialog.manejaError(ex);
        }

    }
    private void doClose(int retStatus) {
        if(retStatus==RET_OK){
            this.setDesde(this.jDesde.getDate());
            this.setHasta(this.jHasta.getDate());
        }
        this.setReturnStatus(retStatus);
        setVisible(false);
        dispose();
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jDesde = new es.atareao.alejandria.gui.JDateChooser();
        jHasta = new es.atareao.alejandria.gui.JDateChooser();
        jLabel3 = new javax.swing.JLabel();
        jMontador = new es.atareao.queensboro.gui.JWrapperComboBox();
        jAceptar = new javax.swing.JButton();
        jCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Planillas Suministradas");
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setText("Desde:");
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 150, 30));

        jLabel2.setText("Hasta:");
        jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 50, 150, 30));
        jPanel1.add(jDesde, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 10, -1, 30));
        jPanel1.add(jHasta, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 50, -1, 30));

        jLabel3.setText("Montador:");
        jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 90, 150, 30));
        jPanel1.add(jMontador, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 90, 200, 30));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 380, 140));

        jAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/es/atareao/img/png/button_ok.png"))); // NOI18N
        jAceptar.setBorderPainted(false);
        jAceptar.setPreferredSize(new java.awt.Dimension(50, 50));
        jAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jAceptarActionPerformed(evt);
            }
        });
        getContentPane().add(jAceptar, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 150, -1, -1));

        jCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/es/atareao/img/png/button_cancel.png"))); // NOI18N
        jCancelar.setBorderPainted(false);
        jCancelar.setPreferredSize(new java.awt.Dimension(50, 50));
        jCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCancelarActionPerformed(evt);
            }
        });
        getContentPane().add(jCancelar, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 150, -1, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jAceptarActionPerformed
        this.doClose(RET_OK);
    }//GEN-LAST:event_jAceptarActionPerformed

    private void jCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCancelarActionPerformed
        this.doClose(RET_CANCEL);
    }//GEN-LAST:event_jCancelarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jAceptar;
    private javax.swing.JButton jCancelar;
    private es.atareao.alejandria.gui.JDateChooser jDesde;
    private es.atareao.alejandria.gui.JDateChooser jHasta;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private es.atareao.queensboro.gui.JWrapperComboBox jMontador;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
    private int _returnStatus = RET_CANCEL;

    /**
     * @return the _desde
     */
    public Date getDesde() {
        return this.jDesde.getDate();
    }

    /**
     * @param desde the _desde to set
     */
    public void setDesde(Date desde) {
        this.jDesde.setDate(desde);
    }

    /**
     * @return the _hasta
     */
    public Date getHasta() {
        return this.jHasta.getDate();
    }

    /**
     * @param hasta the _hasta to set
     */
    public void setHasta(Date hasta) {
        this.jHasta.setDate(hasta);
    }

    /**
     * @return the _returnStatus
     */
    public int getReturnStatus() {
        return _returnStatus;
    }

    /**
     * @param returnStatus the _returnStatus to set
     */
    public void setReturnStatus(int returnStatus) {
        this._returnStatus = returnStatus;
    }

    /**
     * @return the _montador
     */
    public Montador getMontador() {
        return (Montador)this.jMontador.getSelectedItem();
    }

    /**
     * @param montador the _montador to set
     */
    public void setMontador(Montador montador) {
        this.jMontador.setSelectedId(montador.getId());
    }
}
